package com.lz.ad.canal.config.kafka;

import com.lz.common.util.GetCfg;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * Created by Li Tiefei on 2019/3/9.
 */
@Data
@Component
@ConfigurationProperties(prefix = "kafka.producer.connectinfo")
@DependsOn("init")
@Slf4j
public class KafkaProducerConnectionInfo {
    private String bootstrapServers="192.168.10.9:9092,192.168.10.10:9092";
    private int lingerMs=0;
    private int maxRequestSize=1048576;
    private int batchSize=16384;
    private int bufferMemory=33554432;
    private String clientId="lzmh-ad-canal-client";
    private String partitionerClass;
    private String interceptorClasses;

    @PostConstruct
    private void init() {
        bootstrapServers= GetCfg.getDefaultValue("kafka.producer.connectinfo.bootstrapServers", bootstrapServers);
        lingerMs=Integer.parseInt(GetCfg.getDefaultValue("kafka.producer.connectinfo.lingerMs", String.valueOf(lingerMs)));
        maxRequestSize=Integer.parseInt(GetCfg.getDefaultValue("kafka.producer.connectinfo.maxRequestSize", String.valueOf(maxRequestSize)));
        batchSize=Integer.parseInt(GetCfg.getDefaultValue("kafka.producer.connectinfo.batchSize", String.valueOf(batchSize)));
        bufferMemory=Integer.parseInt(GetCfg.getDefaultValue("kafka.producer.connectinfo.bufferMemory", String.valueOf(bufferMemory)));
        // 打印参数
        log.info("kafka producer config: \n" +
                        "bootstrap.servers = {} \n" +
                        "linger.ms = {} \n" +
                        "max.request.size = {} \n" +
                        "batch.size = {} \n" +
                        "buffer.memory = {} \n" +
                        "client.id = {} \n" +
                        "partitioner.class = {} \n" +
                        "interceptor.classes = {} \n",
                bootstrapServers,lingerMs,maxRequestSize,batchSize, bufferMemory,clientId,partitionerClass,interceptorClasses);
    }
}
